package priv.yiyuan.example.design.flyweight;

/**
 * 价格计算策略上下文
 *
 * @author YiYuan
 * @data 2025/9/19
 * @apoNote
 */
public class ShoppingCart {

    private PriceCalculationStrategy strategy;

    private double totalAmount;

    public ShoppingCart(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public void setStrategy(PriceCalculationStrategy strategy) {
        this.strategy = strategy;
    }

    public double checkout() {
        if (strategy == null) {
            System.out.println("未设置价格计算策略, 按原价结算。");
            return totalAmount;
        }

        System.out.println("使用策略进行结算...");
        return strategy.calculatePrice(totalAmount);
    }

}
